﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Edge.Business.Entities;
using Edge.Common.Services;
using Edge.Common.Utils;
using Iesi.Collections.Generic;
using Shop.Business.Domain.Customers;
using Shop.Business.Domain.Orders;

namespace Shop.Business.Domain.Orders
{
    /// <summary>
    /// Users object for NHibernate mapped table 'order'.
    /// </summary>
    [Serializable]
    public class Order : EntityWithStat<int>
    {

        protected int discount;
        protected OrderStatus orderStatus;
        protected string note;
        protected string customerName;
        protected string customerContact;
        protected string deliveryAddress;
        protected decimal total;
        protected CustomerAddress customerAddress;
        protected DeliveryType deliveryType;
        protected PaymentType paymentType;
        protected ISet<OrderItem> items = new HashedSet<OrderItem>();
        protected DateTime deliveryDate = DateTime.Now.AddDays(2);

        public virtual string CustomerName
        {
            get { return customerName; }
            set { customerName = value; }
        }

        public virtual string CustomerContact
        {
            get { return customerContact; }
            set { customerContact = value; }
        }

        public virtual string DeliveryAddress
        {
            get { return deliveryAddress; }
            set { deliveryAddress = value; }
        }

        public virtual int Discount
        {
            get { return discount; }
            set { discount = value; }
        }

        public virtual OrderStatus OrderStatus
        {
            get { return orderStatus; }
            set { orderStatus = value; }
        }

        public virtual string Note
        {
            get { return note; }
            set { note = value; }
        }

        public virtual decimal Total
        {
            get { return items.Sum(i => i.Price); }
            set { total = value; }
        }

        public virtual CustomerAddress CustomerAddress
        {
            get { return customerAddress; }
            set { customerAddress = value; }
        }

        public virtual PaymentType PaymentType
        {
            get { return paymentType; }
            set { paymentType = value; }
        }


        public virtual DeliveryType DeliveryType
        {
            get { return deliveryType; }
            set { deliveryType = value; }
        }

        public virtual ISet<OrderItem> Items
        {
            get
            {
                return items;
            }
            set
            {
                items = value;
            }
        }

        public virtual DateTime DeliveryDate
        {
            get { return deliveryDate; }
            set { deliveryDate = value; }
        }
    }

    public enum PaymentType
    {
        [Description("Наличными")]
        Cash = 1,
        [Description("Безналично")]
        Bank = 2,

    }

    public enum OrderStatus
    {
        [Description("Корзина")]
        Draft = 1,
        [Description("Текущий")]
        Current = 2,
        [Description("Архивный")]
        Archived = 3,
        [Description("Ошибка")]
        Error = 4,
        [Description("Предзаказ")]
        Preorder = 5,

    }
}